CREATE TABLE [dbo].[FACTURAS]
(
[ID] [numeric] (10, 0) NOT NULL,
[ID_CONDICION] [numeric] (10, 0) NOT NULL,
[ID_NCF] [numeric] (10, 0) NOT NULL,
[ID_CLIENTE] [numeric] (10, 0) NOT NULL,
[ID_VENDEDOR] [numeric] (10, 0) NOT NULL,
[ID_USUARIO] [numeric] (10, 0) NOT NULL,
[NRO_FACTURA] [numeric] (10, 0) NOT NULL,
[SEQ_NCF] [numeric] (10, 0) NOT NULL CONSTRAINT [DF_FACTURAS_SEQ_NCF] DEFAULT ((0)),
[FECHA_HORA] [datetime2] (0) NOT NULL CONSTRAINT [DF_FACTURAS_FECHA_HORA] DEFAULT (getdate()),
[FECHA_VENCIMIENTO] [datetime2] (0) NOT NULL CONSTRAINT [DF_FACTURAS_FECHA_VENCIMIENTO] DEFAULT (getdate()),
[COTIZACIONES] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_FACTURAS_COTIZACIONES] DEFAULT (''),
[ORDEN_COMPRA] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_FACTURAS_ORDEN_COMPRA] DEFAULT (''),
[ACTIVO] [bit] NOT NULL CONSTRAINT [DF_FACTURAS_ACTIVO] DEFAULT ((1)),
[OBSERVACIONES] [varchar] (150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_FACTURAS_OBSERVACIONES] DEFAULT (''),
[T_IMPUESTO] [numeric] (10, 2) NOT NULL CONSTRAINT [DF_FACTURAS_T_IMPUESTO] DEFAULT ((0)),
[T_DESCUENTO] [numeric] (10, 2) NOT NULL CONSTRAINT [DF_FACTURAS_T_DESCUENTO] DEFAULT ((0)),
[M_TOTAL] [numeric] (10, 2) NOT NULL CONSTRAINT [DF_FACTURAS_M_TOTAL] DEFAULT ((0)),
[M_PAGADO] [numeric] (10, 2) NOT NULL CONSTRAINT [DF_FACTURAS_M_PAGADO] DEFAULT ((0))
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[FACTURAS] ADD CONSTRAINT [PK_FACTURAS] PRIMARY KEY CLUSTERED  ([ID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_FACTURAS_FECHAS] ON [dbo].[FACTURAS] ([FECHA_HORA]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_FACTURAS_1] ON [dbo].[FACTURAS] ([ID_NCF], [NRO_FACTURA]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_FACTURAS] ON [dbo].[FACTURAS] ([NRO_FACTURA]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[FACTURAS] ADD CONSTRAINT [FK_FACTURAS_CLIENTES] FOREIGN KEY ([ID_CLIENTE]) REFERENCES [dbo].[CLIENTES] ([ID])
GO
ALTER TABLE [dbo].[FACTURAS] ADD CONSTRAINT [FK_FACTURAS_CONDICIONES] FOREIGN KEY ([ID_CONDICION]) REFERENCES [dbo].[CONDICIONES] ([ID])
GO
ALTER TABLE [dbo].[FACTURAS] ADD CONSTRAINT [FK_FACTURAS_NCF] FOREIGN KEY ([ID_NCF]) REFERENCES [dbo].[NCF] ([ID])
GO
ALTER TABLE [dbo].[FACTURAS] ADD CONSTRAINT [FK_FACTURAS_USUARIOS] FOREIGN KEY ([ID_USUARIO]) REFERENCES [dbo].[USUARIOS] ([ID])
GO
ALTER TABLE [dbo].[FACTURAS] ADD CONSTRAINT [FK_FACTURAS_VENDEDORES] FOREIGN KEY ([ID_VENDEDOR]) REFERENCES [dbo].[VENDEDORES] ([ID])
GO
